import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:xiaotiancai/page/ClassPage.dart';
import 'package:xiaotiancai/page/HomePage.dart';
import 'package:xiaotiancai/page/MePage.dart';
import 'package:xiaotiancai/page/MemberShipCenter.dart';
import 'package:xiaotiancai/page/ShoppingCartPage.dart';
import 'package:xiaotiancai/style.dart';
class MainPage extends StatefulWidget {
  const MainPage({super.key});
  @override
  State<MainPage> createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {
  var _currentIndex=0;
  var pages = [
    const HomePage(),
    const ClassPage(),
    const MemberShipCenter(),
    const ShoppingCartPage(),
    const MePage(),
  ];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: IndexedStack(
        index: _currentIndex,
        children: pages,
      ),
      bottomNavigationBar: BottomNavigationBar(
        items: [
          BottomNavigationBarItem(
            label: "首页",
            icon: buildIcon("message",),
            activeIcon: buildIcon("message_focus", isActive: true),
          ),
          BottomNavigationBarItem(
            label: "分类",
            icon: buildIcon("find",),
            activeIcon: buildIcon("find_focus", isActive: true),
          ),
          BottomNavigationBarItem(
            label: "会员中心",
            icon: buildIcon("moment",),
            activeIcon: buildIcon("moment_focus", isActive: true),
          ),
          BottomNavigationBarItem(
            label: "购物车",
            icon: buildIcon("contact",),
            activeIcon: buildIcon("contact_focus", isActive: true),
          ),
          BottomNavigationBarItem(
            label: "我的",
            icon: buildIcon("mine",),
            activeIcon: buildIcon("mine_focus", isActive: true),
          ),
        ],
        currentIndex: _currentIndex,
        selectedItemColor: Style.primaryColor,
        unselectedItemColor: Colors.grey,
        type: BottomNavigationBarType.fixed,
        onTap: (i) {
          if (_currentIndex != i) {
            _currentIndex = i;
            if(_currentIndex!=0&&_currentIndex!=1&&_currentIndex!=4){
              SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
                  statusBarColor: Style.primaryColor,
                  statusBarIconBrightness: Brightness.light));
            }else{
              SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
                  statusBarColor: Colors.transparent,
                  statusBarIconBrightness: Brightness.dark));
            }
            setState(() {});
          }
        },
      ),
    );
  }
  buildIcon(String s, {bool? isActive}) {
    return const Icon(Icons.ac_unit);
  }
}
